﻿<UserControl x:Class="Net.Chirash.Twitter.TweetZone.WindowComponents.ZoneController"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:wc="clr-namespace:Net.Chirash.Twitter.TweetZone.WindowComponents"
             xmlns:media="clr-namespace:System.Windows.Media;assembly=PresentationCore"
             mc:Ignorable="d"
             d:DesignHeight="300" d:DesignWidth="300"
             x:Name="root"
             AllowDrop="True" 
             DataContextChanged="UserControl_DataContextChanged"
             PreviewDragEnter="UserControl_PreviewDragEnter"
             PreviewDragOver="UserControl_PreviewDragOver"
             PreviewDragLeave="UserControl_PreviewDragLeave"
             >
            
    <DockPanel>
        <DockPanel.ContextMenu>
            <ContextMenu>
                <MenuItem Header="InsertTimeline">
                    <MenuItem Header="Home" CommandParameter="Home" Command="{Binding InsertTimelineContainer}" />
                    <MenuItem Header="Mentions" CommandParameter="Mentions" Command="{Binding InsertTimelineContainer}" />
                    <MenuItem Header="DirectMessage" CommandParameter="DirectMessage" Command="{Binding InsertTimelineContainer}" />
                    <MenuItem Header="User" CommandParameter="User" Command="{Binding InsertTimelineContainer}" />
                </MenuItem>
            </ContextMenu>
        </DockPanel.ContextMenu>
        <StackPanel DockPanel.Dock="Top"
                    AllowDrop="True">
            <Border x:Name="TitleBorder"
                    DockPanel.Dock="Top"
                    BorderBrush="{StaticResource WhiteBrush}"
                    BorderThickness="1">
                <DockPanel x:Name="TitlePanel"
                           Background="{StaticResource DarkBrush}"
                           >
                    <wc:RefreshIndicator x:Name="Indicator"
                                     DockPanel.Dock="Left"
                                     Width="20"                                     
                                     IsRefreshing="{Binding Composer.ContainerViewModel.IsRefreshingTask}">
                        <wc:RefreshIndicator.Style>
                            <Style TargetType="{x:Type wc:RefreshIndicator}">
                                <Style.Triggers>
                                    <Trigger Property="IsRefreshing" Value="true">
                                        <Setter Property="Visibility" Value="Visible" />
                                    </Trigger>
                                    <Trigger Property="IsRefreshing" Value="false">
                                        <Setter Property="Visibility" Value="Collapsed" />
                                    </Trigger>

                                </Style.Triggers>
                            </Style>
                        </wc:RefreshIndicator.Style>
                    </wc:RefreshIndicator>

                    <Button x:Name="CloseButton"
                            DockPanel.Dock="Right" 
                            FontWeight="Bold" 
                            Content="×"
                            Command="{Binding CloseContainer}"
                            />

                    <TextBlock x:Name="TimelineTitle"
                           Text="{Binding Composer.ContainerViewModel.ContainerTitle}"
                            Padding="3"
                            >
                        <TextBlock.Style>
                            <Style BasedOn="{StaticResource {x:Type TextBlock}}" TargetType="{x:Type TextBlock}">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Path=Composer.ContainerViewModel.IsRefreshingColumn}" Value="True">
                                        <Setter Property="Background" Value="{StaticResource GreyBrush}" />
                                        <Setter Property="Foreground" Value="{StaticResource DarkBrush}" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding Path=Composer.ContainerViewModel.IsRefreshingColumn}" Value="False">
                                        <Setter Property="Background" Value="{StaticResource DarkBrush}" />
                                        <Setter Property="Foreground" Value="{StaticResource WhiteBrush}" />                
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </TextBlock.Style>

                    </TextBlock>

                </DockPanel>
            </Border>
            <Grid x:Name="ErrorPresentGrid"   
                  Background="{StaticResource WhiteBrush}" >
                <Grid.Style>
                    <Style TargetType="{x:Type Grid}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=Composer.ContainerViewModel.LastErrorMessage.Provider,
                                                           Converter={StaticResource IsNullValueConverterKey}}"
                                         Value="True">
                                <Setter Property="Visibility" Value="Collapsed" />
                            </DataTrigger>
                            <DataTrigger Binding="{Binding Path=Composer.ContainerViewModel.LastErrorMessage.Provider,
                                                           Converter={StaticResource IsNullValueConverterKey}}"
                                         Value="False">
                                <Setter Property="Visibility" Value="Visible" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Grid.Style>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="25" />
                </Grid.ColumnDefinitions>
                <TextBlock x:Name="ErrorTextBlock" Grid.Column="0" 
                       HorizontalAlignment="Left" VerticalAlignment="Center" Margin="2,0,0,0"
                       Background="Transparent" Foreground="{StaticResource DarkBrush}"
                       DataContext="{Binding Composer.ContainerViewModel.LastErrorMessage}" Text="{Binding Message}" />
                <Button x:Name="CloseErrorPresent" Grid.Column="1" Height="25"  Content="×" Command="{Binding ErrorReset}" />
            </Grid>

        </StackPanel>


        <Grid x:Name="body"
              AllowDrop="True"
              MouseLeftButtonDown="body_MouseLeftButtonDown"
              MouseMove="body_MouseMove"
              />
    </DockPanel>

</UserControl>
